package ext.tianma.changeManager.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import wt.part.WTPart;
import wt.session.SessionServerHelper;
import wt.util.WTException;
import wt.workflow.engine.WfProcess;
import ext.tianma.changeManager.constants.ChangeConstants;
import ext.tianma.changeManager.service.ChangeService;
import ext.tianma.changeManager.service.CheckService;
import ext.tianma.changeManager.util.ChangeUtil;
import ext.tianma.changeManager.util.QueryUtil;
import ext.tianma.model.RDPChange;
import ext.tianma.number.util.PartUtil;
import ext.tianma.util.TMUtil;

@Controller
@RequestMapping({ "/ChangeController" })
public class ChangeController {
	@Autowired
	ChangeService changeservice;
	@Autowired
	CheckService checkservice;
	
	private static final org.slf4j.Logger logger = LoggerFactory.getLogger(ChangeController.class);
	
	/**
	 * 接口说明
	 * 
	 * 物料反查：reQueryAPL
	 * 查询文档：findWTDocument
	 * 查询成品：findFinishedWTPart
	 * 属性规则：getLayoutDefinition
	 * 视图查询：getViewByPart
	 * 物料列表：findWTPart
	 * 存储变更：saveRDPChange
	 * 
	 * */
	
	/**
	 * 物料反查
	 * @param aplPartNumber
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年12月1日
	 */
	@RequestMapping(value = "/reQueryAPL", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void reQueryAPL(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("reQueryAPL>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject obj = null;
			JSONObject params = new JSONObject(data);
			String number = ChangeUtil.getJSONString(params, "partNumber");
			String view = ChangeUtil.getJSONString(params, "view");
			if(StringUtils.isNotEmpty(number) && StringUtils.isNotEmpty(view)) {
				WTPart part = PartUtil.getWTPartByNumber(number);
				if(null != part) {
					obj = changeservice.searhMaterialPart(number, view);
				} else {
					obj = ChangeUtil.resFailed("原材料【" + number + "】不存在");
				}
			} else {
				obj = ChangeUtil.resFailed("参数number和view不能为空");
			}
			out.print(obj.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 查询文档(工艺文档、图档类文档)
	 * @param params
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年11月6日
	 */
	@RequestMapping(value = "/findWTDocument", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void findWTDocument(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("findWTDocument>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			
			JSONObject result = null;
			if(StringUtils.isNotEmpty(data)) {
				JSONObject dataObj = new JSONObject(data);
				String type = ChangeUtil.getJSONString(dataObj, "type");//1：根据文档编码查询文档， 2：根据物料查询文档
				if("1".equals(type)) {
					result = changeservice.findWTDocyment(data);
				} else if("2".equals(type)) {
					result = changeservice.findWTDocumentByPart(data);
				} else {
					result = ChangeUtil.resFailed("参数type不能为空");
				}
			} else {
				result = ChangeUtil.resFailed("数据不能为空");
			}
			out.print(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 通过料号查询(工艺文档、图档类文档)
	 * @param data
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年12月23日
	 */
	@RequestMapping(value = "/findWTDocumentByPart", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void findWTDocumentByPart(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("findWTDocumentByPart>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject result = changeservice.findWTDocumentByPart(data);
			out.print(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 查询物料(限制类型，由前端传递)
	 * @param params
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年11月26日
	 */
	@RequestMapping(value = "/findFinishedWTPart", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void findFinishedWTPart(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		/**
		 * 接口名称与功能不协调的背景：
		 * 1、初期该接口仅支持查询成品
		 * 2、中期需求发生变化，接口能查询所有类型部件
		 * 3、后期需求再次变化，前端固定死类型查询
		 * */
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("findFinishedWTPart>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject result = changeservice.findFinishedWTPart(data);
			out.print(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 获取对象属性
	 * @param params
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年11月26日
	 */
	@RequestMapping(value = "/getLayoutDefinition", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void getLayoutDefinition(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
//		response.setHeader("Content-Type", "application/json;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("getLayoutDefinition>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject result = changeservice.getLayoutDefinition(data);
			out.print(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 查询物料所有视图
	 * @param partNumber
	 * @param view
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年12月1日
	 */
	@RequestMapping(value = "/getViewByPart", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void getViewByPart(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("getViewByPart>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject result = changeservice.getViewByPart(data);
			out.print(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 查询物料列表
	 * @param partNumber
	 * @param partName
	 * @param view
	 * @param describe
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年12月1日
	 */
	@RequestMapping(value = "/findWTPart", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void findWTPart(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("findWTPart>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject result = changeservice.findWTPart(data);
			out.print(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 根据rdpId，保存变更数据
	 * @param data
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年12月1日
	 */
	@RequestMapping(value = "/savePartToRDPChange", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void savePartToRDPChange(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("savePartToRDPChange>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject result = changeservice.savePartToRDPChange(data);
			out.print(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 根据rdpId，保存物料数据
	 * @param data
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年12月1日
	 */
	@RequestMapping(value = "/saveDocToRDPChange", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void saveDocToRDPChange(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("saveDocToRDPChange>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject result = changeservice.saveDocToRDPChange(data);
			out.print(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 根据rdpId，查询变更数据
	 * @param rdpId
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年12月1日
	 */
	@RequestMapping(value = "/findPartToRDPChange", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void findPartToRDPChange(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("findPartToRDPChange>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject params = new JSONObject(data);
			String rdpId = ChangeUtil.getJSONString(params, "rdpId");
			JSONObject result = changeservice.findRDPChangeByRdpId(rdpId, ChangeConstants.RDP_MODULE[0]);
			out.print(result);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 流程表单中查看变更表格信息
	 * @param data
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年12月16日
	 */
	@RequestMapping(value = "/findChangeInfo", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void findChangeInfo(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("findPartToRDPChange>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject params = new JSONObject(data);
			String oid = ChangeUtil.getJSONString(params, "oid");
			String wid = ChangeUtil.getJSONString(params, "wid");
			
			WTPart part = (WTPart) TMUtil.oid2Obj(oid);
			WfProcess wf = (WfProcess) TMUtil.oid2Obj(wid);
			String rdpId = (String) wf.getContext().getValue("rdpId");
			String module = (String) wf.getContext().getValue("module");
			String changeData = "";
			RDPChange change = QueryUtil.findRDPChange(TMUtil.oid2Obj(oid), rdpId, module);
			if(null != change) {
				changeData = ChangeUtil.blob2str(change.getChangeInfo());
			}
			JSONArray array = changeservice.findChangeInfo(changeData, part);
			JSONObject result = ChangeUtil.resSuccess(array, "", "暂无数据");
			result.put(ChangeUtil.CODE, "0");//由于前段页面用的layui，按照规范，code应该返回0
			out.print(result);
		} catch (IOException e) {
			e.printStackTrace();
		} catch (WTException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 根据rdpId，查询文档数据
	 * @param data
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年12月11日
	 */
	@RequestMapping(value = "/findDocToRDPChange", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void findDocToRDPChange(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("findDocToRDPChange>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject params = new JSONObject(data);
			String rdpId = ChangeUtil.getJSONString(params, "rdpId");
			JSONObject result = changeservice.findRDPChangeByRdpId(rdpId, ChangeConstants.RDP_MODULE[1]);
			out.print(result);
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 根据rdpId，删除变更数据
	 * @param data
	 * @param response
	 * @throws JSONException
	 * @author xucr
	 * @CreateDate 2020年12月10日
	 */
	@RequestMapping(value = "/delRDPChange", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void delRDPChange(
			@RequestBody String data,
			HttpServletResponse response) throws JSONException {
		response.setContentType("text/html;charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("delRDPChange>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject result = changeservice.delRDPChange(data);
			out.print(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	
	/**----------------------------------------------------------------BOM操作---------------------------------------------------------------*/
	/**
	 * BOM数据校验入口
	 * @param data
	 * @param response
	 * @throws Exception
	 * @author xucr
	 * @CreateDate 2020年12月8日
	 */
	@RequestMapping(value = "/checkBOMData", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void checkBOMData(
			@RequestBody String data,
			HttpServletResponse response) throws Exception {
		response.setContentType("application/json; charset=UTF-8");
		PrintWriter out = response.getWriter();
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("checkBOMData>>>" + data);
		try {
			JSONObject result = checkservice.checkEntrance(data);
			out.print(result.toString());
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * BOM数据保存入口
	 * @param data
	 * @param response
	 * @throws Exception
	 * @author xucr
	 * @CreateDate 2020年12月8日
	 */
	@RequestMapping(value = "/addBOMData", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void addBOMData(
			@RequestBody String data,
			HttpServletResponse response) throws Exception {
		response.setContentType("application/json; charset=UTF-8");
		PrintWriter out = response.getWriter();
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("addBOMData>>>" + data);
		try {
			JSONObject result = changeservice.saveEntrance(data);
			out.print(result.toString());
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 根据rdpId查询所有BOM数据
	 * @param data
	 * @param response
	 * @throws Exception
	 * @author xucr
	 * @CreateDate 2020年12月8日
	 */
	@RequestMapping(value = "/findRDPBOMData", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void findRDPBOMData(
			@RequestBody String data,
			HttpServletResponse response) throws Exception {
		response.setContentType("application/json; charset=UTF-8");
		PrintWriter out = response.getWriter();
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("findRDPBOMData>>>" + data);
		try {
			JSONObject result = null;
			if(StringUtils.isNotEmpty(data)) {
				JSONObject dataObj = new JSONObject(data);
				String rdpId = ChangeUtil.getJSONString(dataObj, "rdpId");
				String bomOption = ChangeUtil.getJSONString(dataObj, "bomOption");
				if(StringUtils.isNotEmpty(rdpId) && StringUtils.isNotEmpty(bomOption)) {
					result = changeservice.queryRDPBOMDataDetail(rdpId, bomOption);
				} else {
					result = ChangeUtil.resFailed("参数rdpId、bomOption不能为空");
				}
			} else {
				result = ChangeUtil.resFailed("数据传输不能为空");
			}
			out.print(result.toString());
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * BOM数据删除入口
	 * @param data
	 * @param response
	 * @throws Exception
	 * @author xucr
	 * @CreateDate 2020年12月11日
	 */
	@RequestMapping(value = "/delBOMData", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void delBOMData(
			@RequestBody String data,
			HttpServletResponse response) throws Exception {
		response.setContentType("application/json; charset=UTF-8");
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("delBOMData>>>" + data);
		try {
			PrintWriter out = response.getWriter();
			JSONObject result = changeservice.delBOMData(data);
			out.print(result.toString());
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 接收RPD数据，启动Windchill流程
	 * @param data
	 * @param response
	 * @throws Exception
	 * @author xucr
	 * @CreateDate 2020年12月11日
	 */
	@RequestMapping(value = "/submitRDPForm", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void submitRDPForm(
			@RequestBody String data,
			HttpServletResponse response) throws Exception {
		response.setContentType("application/json; charset=UTF-8");
		PrintWriter out = response.getWriter();
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("submitRDPForm>>>" + data);
		try {
			JSONObject result = changeservice.submitRDPForm(data);
			out.print(result.toString());
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 根据RDPID，查询对应流程的状况
	 * @param data
	 * @param response
	 * @throws Exception
	 * @author xucr
	 * @CreateDate 2020年12月28日
	 */
	@RequestMapping(value = "/findProcessStatus", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void findProcessStatus(
			@RequestBody String data,
			HttpServletResponse response) throws Exception {
		response.setContentType("application/json; charset=UTF-8");
		PrintWriter out = response.getWriter();
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("submitRDPForm>>>" + data);
		try {
			JSONObject result = changeservice.findProcessStatus(data);
			out.print(result.toString());
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 获取BOM直接子项
	 * @param data
	 * @param response
	 * @throws Exception
	 * @author xucr
	 * @CreateDate 2021年1月27日
	 */
	@RequestMapping(value = "/getChildren", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void getChildren(
			@RequestBody String data,
			HttpServletResponse response) throws Exception {
		response.setContentType("application/json; charset=UTF-8");
		PrintWriter out = response.getWriter();
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("getChildren>>>" + data);
		try {
			JSONObject result = changeservice.getChildren(data);
			out.print(result.toString());
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
	/**
	 * 获取特定替代料
	 * @param data
	 * @param response
	 * @throws Exception
	 * @author xucr
	 * @CreateDate 2021年1月27日
	 */
	@RequestMapping(value = "/getSubstitutes", method = {RequestMethod.POST, RequestMethod.GET })
	@ResponseBody
	public void getSubstitutes(
			@RequestBody String data,
			HttpServletResponse response) throws Exception {
		response.setContentType("application/json; charset=UTF-8");
		PrintWriter out = response.getWriter();
		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
		logger.info("getSubstitutes>>>" + data);
		try {
			JSONObject result = changeservice.getSubstitutes(data);
			out.print(result.toString());
		} finally {
			SessionServerHelper.manager.setAccessEnforced(enforce);
		}
	}
	
//	/**
//	 * 新增物料校验
//	 * @param addNum
//	 * @param amount
//	 * @param effectnumber
//	 * @param view
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月3日
//	 */
//	@RequestMapping(value = "/tmAddCheck", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void tmAddCheck(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = checkservice.checkEntrance(data, ChangeConstants.ADDPart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 新增物料功能
//	 * @param rdpId，RDPID 必填，RDP传输
//	 * @param newaddnum 新增料号，必填
//	 * @param amount 用量，必填
//	 * @param effectnumber 受影响对象，必填
//	 * @param view 视图，必填
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月2日
//	 */
//	@RequestMapping(value = "/tmAddNum", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void tmAddNum(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = changeservice.saveEntrance(data, ChangeConstants.ADDPart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 删除物料校验
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/tmDelCheck", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void tmDelCheck(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = checkservice.checkEntrance(data, ChangeConstants.DelPart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 删除物料功能
//	 * @param rdpId
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/tmDelNum", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void tmDelNum(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = changeservice.saveEntrance(data, ChangeConstants.DelPart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 替换物料校验
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/tmReplaceCheck", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void tmReplaceCheck(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json;charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = checkservice.checkEntrance(data, ChangeConstants.ReplacePart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 替换物料功能
//	 * @param rdpId
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/tmReplaceNum", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void tmReplaceNum(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = changeservice.saveEntrance(data, ChangeConstants.ReplacePart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * BOM：用量修改校验
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/modifyAmountCheck", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void modifyAmountCheck(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = checkservice.checkEntrance(data, ChangeConstants.UpdatePart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * BOM：用量修改功能
//	 * @param rdpId
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/modifyAmount", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void modifyAmount(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = changeservice.saveEntrance(data, ChangeConstants.UpdatePart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * BOM：新增替代料校验
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/addReplacePartCheck", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void addReplacePartCheck(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = checkservice.checkEntrance(data, ChangeConstants.ADDReplcePart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 新增替代料功能
//	 * @param rdpId
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/addReplacePart", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void addReplacePart(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = changeservice.saveEntrance(data, ChangeConstants.ADDReplcePart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 删除替代料校验
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/delReplacePartCheck", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void delReplacePartCheck(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = checkservice.checkEntrance(data, ChangeConstants.DelReplcePart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 删除替代料功能
//	 * @param rdpId
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/delReplacePart", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void delReplacePart(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = changeservice.saveEntrance(data, ChangeConstants.DelReplcePart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 更换替代料校验
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/replaceOldPartCheck", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void replaceOldPartCheck(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = checkservice.checkEntrance(data, ChangeConstants.UpdateReplcePart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 更换替代料功能
//	 * @param rdpId
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/replaceOldPart", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void replaceOldPart(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = changeservice.saveEntrance(data, ChangeConstants.UpdateReplcePart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 更换主料校验
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/repalcePartMainCheck", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void repalcePartMainCheck(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = checkservice.checkEntrance(data, ChangeConstants.UpdateAPart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 更换主料功能
//	 * @param rdpId
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/repalcePartMain", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void repalcePartMain(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = changeservice.saveEntrance(data, ChangeConstants.UpdateAPart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 主次替换校验
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/convertPartMainCheck", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void convertPartMainCheck(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = checkservice.checkEntrance(data, ChangeConstants.ReplaceABPart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
//	
//	/**
//	 * 主次替换功能
//	 * @param rdpId
//	 * @param data
//	 * @param response
//	 * @throws Exception
//	 * @author xucr
//	 * @CreateDate 2020年12月5日
//	 */
//	@RequestMapping(value = "/convertPartMain", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void convertPartMain(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		PrintWriter out = response.getWriter();
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		try {
//			JSONObject result = changeservice.saveEntrance(data, ChangeConstants.ReplaceABPart);
//			out.print(result.toString());
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
	
//	
//	//本地测试类，不能提交
//	@RequestMapping(value = "/test", method = {RequestMethod.POST, RequestMethod.GET })
//	@ResponseBody
//	public void test(
//			@RequestBody String data,
//			HttpServletResponse response) throws Exception {
//		response.setContentType("application/json; charset=UTF-8");
//		boolean enforce = SessionServerHelper.manager.setAccessEnforced(false);
//		logger.info("delBOMData>>>" + data);
//		try {
//			PrintWriter out = response.getWriter();
//			JSONObject obj = new JSONObject(data);
//			String effectnumber = obj.getString("effectnumber");
//			String mainnumber = obj.getString("mainnumber");
//			String substitutesNum = obj.getString("substitutesNum");
//			String view = obj.getString("view");
//			String newAmount = obj.getString("newAmount");
//			
//			BOMBean bean = new BOMBean();
//			bean.setEffectnumber(effectnumber);
//			bean.setMainNum(mainnumber);
//			bean.setSubstitutesNum(substitutesNum);
//			bean.setView(view);
//			bean.setSubNewAmount(newAmount);
//			String eff = BOMECOUpdate.UpdateSubstitutesQuantity(bean);
//			
//			out.print(eff);
//		} catch (IOException e) {
//			e.printStackTrace();
//		} finally {
//			SessionServerHelper.manager.setAccessEnforced(enforce);
//		}
//	}
	
}
